//
//  ViewController.m
//  Archiver
//
//  Created by LiJonius on 16/3/24.
//  Copyright © 2016年 LiJonius. All rights reserved.
//

#import "ViewController.h"
#import "TableViewController.h"
#import "Person.h"
#import "XMLParserViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    //归档
    Student* student = [[Student alloc]init];
    student.name = @"学生1";
    student.age = 5;
    student.schoolName = @"亚特兰蒂斯中学";
    
    Person *encodePerssion = [[Person alloc]init];
    encodePerssion.name = @"张三";
    encodePerssion.age = 5;
    encodePerssion.student = student;
    
    NSMutableData *encodeData = [NSMutableData data];
    NSKeyedArchiver *arch = [[NSKeyedArchiver alloc]initForWritingWithMutableData:encodeData];
    [arch encodeObject:encodePerssion forKey:@"person"];
    [arch finishEncoding];
    
    NSString *encodeFilePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:@"person"];
    [encodeData writeToFile:encodeFilePath atomically:YES];
    
    
    //反归档
    NSString *decodeFilePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:@"person"];
     NSLog(@"%@",decodeFilePath);
    NSData *decodeData = [NSData dataWithContentsOfFile:decodeFilePath];
    NSKeyedUnarchiver *unArch = [[NSKeyedUnarchiver alloc]initForReadingWithData:decodeData];
    Person *decodePersion = [unArch decodeObjectForKey:@"person"];
    
    
    NSLog(@"%@ ---%d -----%@",decodePersion.name,decodePersion.age,decodePersion.student);
    
}
- (IBAction)clickBtnToFileManagerTableVC:(id)sender {
    
//    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:[[TableViewController alloc]init]];
//    [self presentViewController:nav animated:YES completion:nil];
   [self.navigationController pushViewController:[[TableViewController alloc]init] animated:YES];
}
- (IBAction)clickButtonToParserXMLVC:(id)sender {
    
//    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:[[XMLParserViewController alloc]init]];
//    [self presentViewController:nav animated:YES completion:nil];
    [self.navigationController pushViewController:[[XMLParserViewController alloc]init] animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
